package com.ruoyi.life.service.manager;

import cn.hutool.core.date.DateUtil;
import com.ruoyi.common.redis.service.RedisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

@Service
public class BillManager {

    @Autowired
    private RedisService redisService;

    //生成流水单号
    public String genLeaseNumber(String code) {
        String date = DateUtil.format(DateUtil.date(), "yyyyMMdd");
        String key = code + "-" + date;
        Integer v = redisService.getCacheObject(key);

        String result = "";
        if (v == null) {
            v = 0;
            redisService.setCacheObject(key, v, 24L, TimeUnit.HOURS);
        } else {
            v = v + 1;
            redisService.setCacheObject(key, v);
        }
        String fs = String.format("%03d", v);
        result = code + date + fs;
        return result;
    }
}
